import studentList from '@/assets/request/statusList.js'
const ExportJsonExcel = require("js-export-excel");

let STUDENT_NAME = {
    "createTime": "注册时间",
    "currentGrade": "等级标记",
    "highVipTime": "变动时间",
    "id": 'id',
    "isValid": "是否毕业",
    "isVip": "是否是VIP",
    "middleVipTime": "充值时间",
    "mobile": "手机号",
    "name": "姓名",
    "primaryVipTime": "更新时间",
    "schoolName": "校区名称",
    "schoolNo": "校区编号",
    "status": "状态",
    "studentNo": "学生编号",
    "userid": "用户ID",
    "vipDeadTime": "充值时间",
    "vipGrade": "vip状态"
}

export function getStudentData(query) {
    let { pageIdx, pageSize } = query

    return new Promise((res) => {
        let obj = {
            "code": 200,
            "data": {
                "content": studentList.splice(pageIdx, pageSize),
                "page": pageIdx,
                "size": pageSize,
                "totalPages": 50 / pageSize,
                "totalRecords": 50
            },
            "msg": "success"
        }
        setInterval(() => {
            res(obj)
        }, 1000);
    })
}

export function setDownLoadData(query) {
    let { title, tableData, columnWidths = [8, 6, 6, 6, 6, 6, 6, 6, 6, 6] } = query
    let sheetFilter = []
    let sheetHeader = []
    for (const key in STUDENT_NAME) {
        sheetFilter.push(key)
        sheetHeader.push(STUDENT_NAME[key])
    }

    var option = {}

    option.fileName = title
    option.datas = [
        {
            sheetData: tableData,
            sheetName: "sheet",
            sheetFilter: sheetFilter,
            sheetHeader: sheetHeader,
            columnWidths: columnWidths,
        },
    ];

    var toExcel = new ExportJsonExcel(option) //new
    toExcel.saveExcel() //保存
}